<script type="text/javascript">
	$(document).ready(function() {
            $('.fancybox-media').fancybox({
              openEffect	: 'elastic',
              closeEffect	: 'elastic',
		helpers : {
			media : {}
		},
                margin      : 50
            });
           $(".various").fancybox({
              closeClick  : false,
              openEffect	: 'elastic',
              closeEffect	: 'elastic',
              width		: '80%',
              closeBtn          : true,
              height		: '80%',
              type              :'iframe',
              'afterClose' : function() {
                parent.location.reload(true);
              },
              helpers   : {
                overlay : {closeClick: false}
              },
              'hideOnContentClick': true
            });
            $(".research").fancybox({
              closeClick  : true,
              openEffect	: 'elastic',
              closeEffect	: 'elastic',
              width		: '80%',
              closeBtn          : true,
              //height		: '80%',
              type              :'iframe',
              helpers   : {
                overlay : {closeClick: false}
              }
            });
	});
</script>
<!-- Inicio Codigo feo para FB-->
  <div id="fb-root"></div>
  <script>
    (function(d, s, id) {
       var js, fjs = d.getElementsByTagName(s)[0];
       if (d.getElementById(id)) return;
       js = d.createElement(s); js.id = id;
       js.src = "//connect.facebook.net/es_LA/all.js#xfbml=1&appId=151090545023142";
       fjs.parentNode.insertBefore(js, fjs);
    }(document, 'script', 'facebook-jssdk'));
  </script>

    <% ruta_root = "http://200.16.7.111"%>
    <% ruta = ruta_root+'/cultural_heritage/collections/'+@cultural_heritage_collection.id.to_s %>
    <% titulo= '<meta property="og:title" content="'+@cultural_heritage_collection.title_name_code+'" >'%>
    <%=  content_for(:title) {
     titulo.html_safe
     } %>
    <% url= '<meta property="og:url" content="'+ruta+'">'%>
    <%=  content_for(:url) {
     url.html_safe
    } %>
    <%=  content_for(:type) {
     '<meta property="og:type" content="article">'.html_safe
    } %>
    <%imagen = '<meta property="og:image" content="'+ruta_root+'/images/pukara_logo2.png">'%>
    <%=  content_for(:image) {
     imagen.html_safe
    } %>
    <%=  content_for(:site_map) {
     '<meta property="og:site_name" content="Pukara">'.html_safe
    } %>
<!-- Fin Codigo feo para FB-->
<!-- Inicio codigo para el Google MAPS -->
<%= stylesheet_link_tag 'gmaps4rails' %>
<!-- Fin codigo para el Google MAPS -->

<% if flash[:notice] %>
    <div id="notice"><%= flash[:notice] %></div>
<% end %>

<!--Datos de Galería-->
<div class="shadow">
  <fieldset id="agrupacion">
    <legend>Datos</legend>
    <fieldset class="column-left" >
      <%if @cultural_heritage_collection.name %>
      <p>
        <b>Nombre:</b>
        <%= @cultural_heritage_collection.name %>
      </p>
      <%end%>

      <%if @cultural_heritage_collection.description %>
      <p>
        <b>Descripción:</b>
        <%= @cultural_heritage_collection.description %>
      </p>
      <%end%>

      <% if @cultural_heritage_collection.original_size %>
      <p>
        <b>Tamaño original en unidades:</b>
        <%= @cultural_heritage_collection.original_size %>
      </p>
      <%end%>

      <% if @cultural_heritage_collection.current_size %>
      <p>
        <b>Tamaño actual en unidades:</b>
        <%= @cultural_heritage_collection.current_size %>
      </p>
      <%end%>
    </fieldset>
    <fieldset class="column-right" >
      <% if@cultural_heritage_collection.str_owner %>
      <p>
        <b>Propietario:</b>
        <%= @cultural_heritage_collection.str_owner %>
      </p>
      <%end%>

      <% if @cultural_heritage_collection.str_state %>
      <p>
        <b>Estado:</b>
        <%= @cultural_heritage_collection.str_state %>
      </p>
      <%end%>

      <% if @cultural_heritage_collection.cultural_institution %>
      <p>
        <b>Institución Cultural:</b>
        <%= link_to @cultural_heritage_collection.str_cultural_institution,{:controller=>"/cultural_heritage/cultural_institutions",:action => 'show',:id => @cultural_heritage_collection.cultural_institution},:title => @cultural_heritage_collection.str_cultural_institution %>        
      </p>
      <%end%>
    </fieldset>

  </fieldset>
</div>

<!--Galería de la Colección completa-->
<div class="shadow">
  <% if @cultural_heritage_collection.cultural_heritages.size > 0 %>
  <fieldset id="agrupacion">
    <legend>Colección completa</legend>
      <%if @cultural_heritage_collection_photos.size > 0%>
        <div class="imageRow img_row_vert">
          <div class="set">
              <%count = 0%>
              <% @cultural_heritage_collection_photos.each do |cultural_heritage_collection_photo| %>
                
                <%if count.eql?(0)
                      @div_class = " first"
                  elsif count.eql?(@cultural_heritage_collection_photos.size-1)
                      @div_class = " last"
                  else
                      @div_class = ""
                  end %>

                <div class="single<%= @div_class %>">
                  <a href="<%=cultural_heritage_collection_photo.photo.url%>" rel="lightbox[banners]"
                     title="<%=cultural_heritage_collection_photo.title + (cultural_heritage_collection_photo.description.blank? ? " " : " : "+cultural_heritage_collection_photo.description) %>">
                     <img alt="<%=cultural_heritage_collection_photo.title + (cultural_heritage_collection_photo.description.blank? ? " " : " : "+cultural_heritage_collection_photo.description) %>"
                         class="thumb" src="<%=cultural_heritage_collection_photo.photo.url%>" />
                  </a>
                  <span class="delete_photo" style="display: none;" >
                    <%= link_to image_tag("navi/cross-16-ns.png", :border => 0, :title => 'Eliminar', :alt => 'Eliminar'), "/cultural_heritage/collections/delete_photo/"+cultural_heritage_collection_photo.id.to_s, :confirm => "Está seguro de eliminar dicha foto?" %>
                  </span>
                </div>
                <%count += 1%>
              <%end%>
          </div>
        </div>
      <%else%>
        <p>No se encontraron fotos para mostrar.</p>
      <%end%>

    <% if user_signed_in? && CulturalHeritage::CollectionsController.edit_roles.include?(current_user.role)%>      
      <%= link_to 'Añadir Fotos', {:controller=>"/cultural_heritage/collections",:action => 'new_photo',:id =>@cultural_heritage_collection.id},:class =>'various', :remote =>true %>
      <%= link_to 'Eliminar Foto', "javascript:toggle();" %>
    <%end%>
  </fieldset>
  <%end%>
</div>

<!--Maps para cada mapa: -->
<div class="shadow">
  <% if @cultural_heritage_collection.cultural_heritages.size > 0 %>
  <%#if (@cultural_heritage_cultural_institution.gmaps == true) or !(@cultural_heritage_cultural_institution.address.blank? and @cultural_heritage_cultural_institution.department.blank? and  @cultural_heritage_cultural_institution.province.blank? and  @cultural_heritage_cultural_institution.district.blank?) %>
  <fieldset id="agrupacion">
    <legend>Ubicación</legend>   
    
    <%= gmaps({
        "map_options" => { "type" => "HYBRID", "center_longitude" => 180, "zoom" => 7, "auto_adjust" => true, "autp_zoom" => true},
        "markers"     => { "data" => @json,
                           "options" => { "list_container" => "markers_list",
                                          "custom_infowindow_class" => "info_window1"
                                        }
                          }
      })%>

    <%#*<div class="shadow">%>
      <ul id="markers_list" class="mrks_list_vertical"> </ul>
    <%#*</div>%>

  </fieldset>
  <%end%>
</div>

<!--Galería de fotos de los bienes integrantes de la colección:-->
<div class="shadow">
  <%#*<fieldset id="agrupacion">%>
    <%#*<legend>Composici&oacute;n</legend>%>

      <% if @cultural_heritage_collection.cultural_heritages.size > 0 %>

          <% @cultural_heritage_collection.cultural_heritages.each do |cultural_heritage| %>
            <fieldset id="agrupacion" >
              <legend>Miembro</legend>
              <fieldset >

                <fieldset class="column-left" >
                  <%if !cultural_heritage.nationalRegistrationCode.blank?%>
                  <p>
                    <b>Código de Registro Nacional:</b>
                      <%= link_to cultural_heritage.nationalRegistrationCode,{:controller=>"/cultural_heritage/cultural_heritages",:action => 'show',:id => cultural_heritage.id},:title => cultural_heritage.description%>
                  </p>
                  <%end%>

                  <%if !cultural_heritage.name.blank?%>
                  <p>
                    <b>Nombre:</b>
                      <%= cultural_heritage.name %>
                  </p>
                  <%end%>
                </fieldset>

                <fieldset class="column-right" >
                  <%if !cultural_heritage.description.blank?%>
                  <p>
                    <b>Descripci&oacute;n:</b>
                      <%= cultural_heritage.description %>
                  </p>
                  <%end%>
                </fieldset>

                </fieldset>

            <% if cultural_heritage.list_avatars.size > 0 %>
              <div class="imageRow img_row_vert">
                  <div class="set">

                  <% @index = 0
                    @div_class = "" %>

                  <% cultural_heritage.list_avatars.each do |cultural_heritage_avatar| %>

                      <%if @index.eql?(0)
                            @div_class = " first"
                        elsif @index.eql?(cultural_heritage.list_avatars.size-1)
                            @div_class = " last"
                        else
                            @div_class = ""
                        end %>

                      <div class="single<%= @div_class %>">
                          <a href="<%=cultural_heritage_avatar.avatar.url%>" rel="lightbox<%= "["+cultural_heritage.id.to_s+"]" %>" title="<%=cultural_heritage_avatar.title%>">
                            <img class="thumb" src="<%=cultural_heritage_avatar.avatar.url%>" alt="<%=cultural_heritage_avatar.description%>" />
                          </a>
                      </div>
                     <% @index += 1 %>
                  <%end%>

                  </div>
              </div>
            <%end%>

            </fieldset>

          <%end%>
      <%end%>

  <%#*</fieldset>%>
</div>

<div id="lineaform"></div>
<!-- Facebook Inicia aqui -->
<div class="fb-comments" data-href="<%=ruta%>" data-num-posts="4" data-width="470"></div>
<div id="lineaform"></div>
<!-- Menu inferior-->
<% if user_signed_in? && CulturalHeritage::CollectionsController.edit_roles.include?(current_user.role)%>
  <%= link_to 'Editar', edit_cultural_heritage_collection_path(@cultural_heritage_collection) %> |
  <%= link_to 'Asignar', :controller=>"/cultural_heritage/collections",:action => 'assing',:id =>@cultural_heritage_collection.id %> |
  <% if @cultural_heritage_collection.cultural_heritages.size > 0 %>
    <%= link_to 'Galería', :controller=>"/cultural_heritage/collections",:action => 'new_photo',:id =>@cultural_heritage_collection.id %> |
  <%end%>
<%end%>
<%= link_to 'Exportar a PDF',{:controller => '/report/collections_report', :action => 'show_pdf', :id => @cultural_heritage_collection.id}%> |
<%= link_to 'Regresar', cultural_heritage_collections_path %>


<script type="text/javascript">
  //Mostrar las opciones de eliminar foto
        function toggle() {
          elems = $(".delete_photo");
          for(i=0; i < elems.length; i++)
            elems[i].style.display = (elems[i].style.display != 'none' ? 'none' : '' );
        }

        /*
        function toggle(obj) {
          var el = document.getElementById(obj);
          el.style.display = (el.style.display != 'none' ? 'none' : '' );
        }
         */

  //Gmaps
    Gmaps.map.infobox = function(boxText) {
      return {
         content: boxText
        ,disableAutoPan: false
        ,maxWidth: 0
        ,pixelOffset: new google.maps.Size(-140, 0)
        ,zIndex: null
        ,boxStyle: {
          background: "url('http://google-maps-utility-library-v3.googlecode.com/svn/tags/infobox/1.1.5/examples/tipbox.gif') no-repeat"
          ,opacity: 0.75
          ,width: "280px"
           }
        ,closeBoxMargin: "10px 2px 2px 2px"
        ,closeBoxURL: "http://www.google.com/intl/en_us/mapfiles/close.gif"
        ,infoBoxClearance: new google.maps.Size(1, 1)
        ,isHidden: false
        ,pane: "floatPane"
        ,enableEventPropagation: false
     }};
</script>